// ignore_for_file: dangling_library_doc_comments, slash_for_doc_comments

/*** 
 * @Author: Zhong
 * @Date: 2025-05-14 17:34:32
 * @LastEditors: Zhong zhongxiaodong@eenet.com
 * @LastEditTime: 2025-07-11 15:37:18
 * @FilePath: /wan_android_flutter/lib/common_code/router/routers.dart
 * @Description: 
 */

import 'package:flutter/cupertino.dart';

import '../../module_code/home/pages/home_page.dart';
import '../../module_code/login/pages/login_page.dart';
import '../../module_code/mine/pages/mine_page.dart';
import '../tabbar/bottom_nav_tabbar.dart';

/// 路由配置
final Map routers = {
  LoginPage.routeName: (context,{arguments}) => LoginPage(arguments: arguments),
  BottomNavTabbar.routeName: (context) => BottomNavTabbar(),
  HomePage.routeName: (context) => HomePage(),
  MinePage.routeName: (context) => MinePage(),
};

class Routers {
  //  路由跳转拦截
  static Route<dynamic>? onGenerateRoute(RouteSettings settings) {
    final String? name = settings.name;// 路由名称
    final Function? pageContentBuilder = routers[name];// 对应的方法
    // 判断路由是否存在
    if (pageContentBuilder != null) {
      //  判断是否带参数
      if (settings.arguments != null) {
        // 参数传递
        final Route route = CupertinoPageRoute(
            builder: (context) =>
                pageContentBuilder(context, arguments: settings.arguments));
        return route;
      } else {
        // 无参数
        final Route route =
            CupertinoPageRoute(builder: (context) => pageContentBuilder(context));
        return route;
      }
    }
    return null;
  }
}
